package com.macro.mall.demo.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.demo.dto.PmsBrandDto;
import com.macro.mall.demo.service.HomeService;
import com.macro.mall.model.HomeContenResult;
import com.macro.mall.model.PmsBrand;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *商品  管理
 */
@Tag(name = "DemoController", description = "商品管理示例接口")
@Controller
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);

    @Operation(summary = "获取首页信息")
    @RequestMapping(value = "/content", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<HomeContenResult> getHomeContent() {
        return CommonResult.success(homeService.getHomeContent());
    }

//    @Operation(summary = "根据编号查询品牌信息")
//    @RequestMapping(value = "/brand/detail/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
//        return CommonResult.success(homeService.getBrand(id));
//    }

//    @Operation(summary = "添加品牌")
//    @RequestMapping(value = "/brand/create", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult createBrand(@Validated @RequestBody PmsBrandDto pmsBrand) {
//        CommonResult commonResult;
//        int count = demoService.createBrand(pmsBrand);
//        if (count == 1) {
//            commonResult = CommonResult.success(pmsBrand);
//            LOGGER.debug("createBrand success:{}", pmsBrand);
//        } else {
//            commonResult = CommonResult.failed("操作失败");
//            LOGGER.debug("createBrand failed:{}", pmsBrand);
//        }
//        return commonResult;
//    }
//
//    @Operation(summary = "更新品牌")
//    @RequestMapping(value = "/brand/update/{id}", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandDto pmsBrandDto) {
//        CommonResult commonResult;
//        int count = demoService.updateBrand(id, pmsBrandDto);
//        if (count == 1) {
//            commonResult = CommonResult.success(pmsBrandDto);
//            LOGGER.debug("updateBrand success:{}", pmsBrandDto);
//        } else {
//            commonResult = CommonResult.failed("操作失败");
//            LOGGER.debug("updateBrand failed:{}", pmsBrandDto);
//        }
//        return commonResult;
//    }
//
//    @Operation(summary = "删除品牌")
//    @RequestMapping(value = "/brand/delete/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult deleteBrand(@PathVariable("id") Long id) {
//        int count = demoService.deleteBrand(id);
//        if (count == 1) {
//            LOGGER.debug("deleteBrand success :id={}", id);
//            return CommonResult.success(null);
//        } else {
//            LOGGER.debug("deleteBrand failed :id={}", id);
//            return CommonResult.failed("操作失败");
//        }
//    }
//
//    @Operation(summary = "分页获取品牌列表")
//    @RequestMapping(value = "/brand/list", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<CommonPage<PmsBrand>> listBrand(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
//                                                        @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
//        List<PmsBrand> brandList = demoService.listBrand(pageNum, pageSize);
//        return CommonResult.success(CommonPage.restPage(brandList));
//    }
//
//    @Operation(summary = "根据编号查询品牌信息")
//    @RequestMapping(value = "/brand/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
//        return CommonResult.success(demoService.getBrand(id));
//    }
}
